import { defineStore } from 'pinia'
import router from "../router"
import { login,getRoleById } from "@/api/api"
const routeArr = [
    {
      path: "password",
      component: () => import("@/views/Password.vue"),
      meta:{label:"密码管理"}
    },
    
    {
      path: 'role',
      component: () => import("@/views/role.vue"),
      meta:{label:"角色管理"}
    },
    {
      path: 'manager',
      component: () => import("@/views/Manager.vue"),
      meta:{label:"成员管理"}
    },
    
    {
      path: 'menu',
      component: () => import("@/views/Menu.vue"),
      meta:{label:"密码管理"}
    },
    {
      path: 'Banner',
      component: () => import("@/views/Banner.vue"),
      meta:{label:"轮播管理"}
    },
    {
      path: 'classify',
      component: () => import("@/views/classify.vue"),
      meta:{label:"分类管理"}
    },
    {
      path: 'Goods',
      component: () => import("@/views/Goods.vue"),
      meta:{label:"商品管理"}
    },
  ] 
export const useRouteStore = defineStore('alerts', {
    state: () => ({menu:[]  }),
    actions: {
        addRoutes:async function (rid:number){
            const role=await getRoleById(rid);
             this.menu=JSON.parse(role.data.data.menu)
            routeArr.forEach(v=>{
                if(this.menu.includes(v.meta.label)){
                    router.addRoute("main",v)
                }
            })
        }
    },
})